import hashlib
import sys
import six

PY2 = sys.version_info[0] == 2

md5string = lambda x: hashlib.md5(utf8(x)).hexdigest()

def utf8(string):
    """
    Make sure string is utf8 encoded bytes.

    If parameter is a object, object.__str__ will been called before encode as bytes
    """
    if isinstance(string, six.text_type):
        return string.encode('utf8')
    elif isinstance(string, six.binary_type):
        return string
    else:
        return six.text_type(string).encode('utf8')

md5 = md5string("https://www.imdb.com/title/tt7349662/?ref_=adv_li_i")
print(md5)